package com.trainfinder.requestor;

public class ExtractMoved implements Extractor {

	/* (non-Javadoc)
	 * @see Requestor.Extractor#extract(java.lang.String)
	 */
	public String extract(String data) {
		String result = "";
		if (data.startsWith("HTTP/1.1 302")) {
			final String STARTS_WITH = "Location: http://";
			final String FROM = "Location: ";
			final String ENDS_WITH = "\r";

			
			int start = data.indexOf(STARTS_WITH);

			if (start != -1) {
				int end = data.indexOf(ENDS_WITH, start + FROM.length());

				if (end != -1) {
					result = data.substring(start+ FROM.length(), end);
				}

			}
		}
		return result;
	}

}
